package Demo2;

import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-07-25
 * Time: 14:43
 */
public class Test {

    public static void initArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length - i;
        }
    }

    public static void initNoArray(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }

    public static long insetTimeSpent(int[] array){
        int[] arr = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.insetSort(arr);
        long end = System.currentTimeMillis();
        return end - start;
    }

    public static long shellTimeSpent(int[] array){
        int[] arr = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.shellSort(array);
        long end = System.currentTimeMillis();
        return end - start;
    }

    public static long selectTimeSpent(int[] array){
        int[] arr = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.selectSort(array);
        long end = System.currentTimeMillis();
        return end - start;
    }

    public static long heapTimeSpent(int[] array){
        int[] arr = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.heapSort(array);
        long end = System.currentTimeMillis();
        return end - start;
    }

    public static long quickTimeSpent(int[] array){
        int[] arr = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.quickSort(array);
        long end = System.currentTimeMillis();
        return end - start;
    }

    public static long mergeTimeSpent(int[] array){
        int[] arr = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.mergeSortNor(array);
        long end = System.currentTimeMillis();
        return end - start;
    }

    public static long bubbleTimeSpent(int[] array){
        int[] arr = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.bubbleSort(array);
        long end = System.currentTimeMillis();
        return end - start;
    }

    /**
     * 用来测试各种排序方法的效率
     * @param args
     */
    public static void main2(String[] args) {
        int[] array = new int[10_0000];
        initNoArray(array);
//        System.out.println("插入排序耗时：" + insetTimeSpent(array));
        System.out.println("希尔排序耗时：" + shellTimeSpent(array));
//        System.out.println("选择排序耗时：" + selectTimeSpent(array));
        System.out.println("堆排序耗时：" + heapTimeSpent(array));
        System.out.println("快速排序耗时：" + quickTimeSpent(array));
//        System.out.println("冒泡排序耗时：" + bubbleTimeSpent(array));
        System.out.println("归并排序耗时：" + mergeTimeSpent(array));

    }

    /**
     * 用来简单进行测试，判断排序是否正确
     * @param args
     */
    public static void main(String[] args) {
//        int[] array1 = {12,3,4,5,6,73,35};
//        System.out.println("排序前" + Arrays.toString(array1));
//        Sort.insetSort(array1);
//        System.out.println("排序后" + Arrays.toString(array1));
//        int[] array2 = {12,3,4,5,6,73,35};
//        System.out.println("==============================");
//        System.out.println("排序前" + Arrays.toString(array2));
//        Sort.shellSort(array2);
//        System.out.println("排序后" + Arrays.toString(array2));
//        System.out.println("==============================");
//        int[] array3 = {12,3,4,5,6,73,35};
//        System.out.println("排序前" + Arrays.toString(array3));
//        Sort.selectSort(array3);
//        System.out.println("排序后" + Arrays.toString(array3));
//        System.out.println("==============================");
//        int[] array4 = {12,3,4,5,6,73,35};
//        System.out.println("排序前" + Arrays.toString(array4));
//        Sort.heapSort(array4);
//        System.out.println("排序后" + Arrays.toString(array4));
//        System.out.println("==============================");
//        int[] array5 = {6,1,2,7,9,3,4,5,10,8};
//        System.out.println("排序前" + Arrays.toString(array5));
//        Sort.quickSort(array5);
//        System.out.println("排序后" + Arrays.toString(array5));
//        System.out.println("==============================");
//        int[] array6 = {6,1,2,7,9,3,4,5,10,8};
//        System.out.println("排序前" + Arrays.toString(array6));
//        Sort.bubbleSort(array6);
//        System.out.println("排序后" + Arrays.toString(array6));
//        System.out.println("==============================");
        int[] array7 = {10,6,7,1,3,9,4};
        System.out.println("排序前" + Arrays.toString(array7));
        Sort.mergeSortNor(array7);
        System.out.println("排序后" + Arrays.toString(array7));
//        int[] array8 = {6,1,2,7,9,3,4,5,10,8};
//        System.out.println("排序前" + Arrays.toString(array8));
//        Sort.quickSortNor(array8);
//        System.out.println("排序后" + Arrays.toString(array8));
        int[] array9 = {10,6,7,1,3,9,4};
        System.out.println("排序前" + Arrays.toString(array9));
        Sort.countSort(array9);
        System.out.println("排序后" + Arrays.toString(array9));
    }
}
